﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace BaoJian.WebManager.Function.ExProduct
{
    public partial class AllHotEx : System.Web.UI.Page
    {
        private string ColumnID = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            ColumnID = HttpContext.Current.Request.QueryString["oid"];
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        void BindData()
        {
           // LYQ.BLL.VHotExchange bll = new LYQ.BLL.VHotExchange();
            //LYQ.Model.VHotExchange model = new LYQ.Model.VHotExchange();
            string sql = string.Format("SELECT DISTINCT [PColumn],sid,[TopProduct],[ProductName],[RegDate], [Deadline],[CustomerID],[TotalNum],[Price] FROM [VHotExchange] WHERE  PColumn='{0}' order by TopProduct desc,sid DESC", ColumnID);
            GridView1.DataSource = Maticsoft.DBUtility.DbHelperSQL.Query(sql).Tables[0]; // bll.GetList("PColumn='" + ColumnID + "' order by TopProduct desc,sid desc");
            GridView1.DataBind();
         
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }

        protected void SetTop_Click(object sender, EventArgs e)
        {
            string sel = HttpContext.Current.Request.Form["Top2CB"];
            if (sel == null)
            {
                return;
            }
            string[] sels = sel.Split(',');

            LYQ.BLL.RecommendProduct bll = new LYQ.BLL.RecommendProduct();

            for (int i = 0; i < sels.Length; i++)
            {
                LYQ.Model.RecommendProduct model = bll.GetModel(Convert.ToInt32(sels[i]), ColumnID);
                model.TopProduct = true;
                bll.Update(model);
            }
            BindData();
        }

        protected void DelTop_Click(object sender, EventArgs e)
        {
            string sel = HttpContext.Current.Request.Form["Top2CB"];
            if (sel == null)
            {
                return;
            }
            string[] sels = sel.Split(',');

            LYQ.BLL.RecommendProduct bll = new LYQ.BLL.RecommendProduct();
         
            for (int i = 0; i < sels.Length; i++)
            {
                LYQ.Model.RecommendProduct model = bll.GetModel(Convert.ToInt32(sels[i]), ColumnID);                          
                model.TopProduct = false;
                bll.Update(model);               
            }
            BindData();
        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            string sel = HttpContext.Current.Request.Form["selectCB"];
            if (sel == null)
            {
                return;
            }
            string[] sels = sel.Split(',');

            LYQ.BLL.RecommendProduct bll = new LYQ.BLL.RecommendProduct();
            for (int i = 0; i < sels.Length; i++)
            {
               bll.Delete(Convert.ToInt32(sels[i]), ColumnID);
            }
            BindData();
        }
    }
}
